<template>
	<view class="">
		<scroll-view scroll-y @scrolltolower="handleToLower" class="album_scroll_view">
		
		
			<u-tabs class="tab-style" :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
			<!-- 未解决 -->
			<view v-show="current === 0">
		
				<view class="comment" v-for="(res, index) in commentList" :key="res.id" v-if="loading">
					<view class="left">
						<image :src="res.userUrl" mode="aspectFill"></image>
					</view>
					<view class="right">
						<view class="top">
							<view class="name">{{ res.createName }}</view>
							<text class="text"> {{ res.createDate }}</text>
						</view>
						<view class="content">{{ res.question }}</view>
		
						<view v-if="res.imgUrls != null">
							<view class="card-body-img-col3" v-if="res.imgList.length > 1">
								<view class="card-body-img-col3-item" v-for="item in splitImgArr(res.imgList)" :key="item">
									<view v-for="item2 in item" :key="item2">
										<u-image @click="showPic(item2,index)" width="100%" height="200rpx" :src="item2">
										</u-image>
									</view>
								</view>
							</view>
							<view class="card-body-img-col1" v-else>
								<u-image @click="showPic(res.imgList[0],index)" width="100%" height="250rpx"
									:src="res.imgList[0]">
								</u-image>
							</view>
						</view>
		
		
		
						<view class="reply-box" v-if="res.status!=0">
							<view class="item">
								<view class="username">{{ res.answerName }}</view>
								<view class="text">{{ res.answer }}</view>
							</view>
						</view>
						<view class="bottom" v-if="res.status!=0">
							回应时间：{{ res.updateDate }}
						</view>
					</view>
				</view>
		
		
				<u-divider  v-if= "!hasMore" class="index-list-divider" text="没有更多了">
					
				</u-divider>
			</view>
			<!-- 已解决 -->
			<view v-show="current === 1">
				
				<view class="comment" v-for="(res, index) in commentList" :key="res.id" v-if="loading">
					<view class="left">
						<image :src="res.userUrl" mode="aspectFill"></image>
					</view>
					<view class="right">
						<view class="top">
							<view class="name">{{ res.createName }}</view>
							<text class="text"> {{ res.createDate }}</text>
						</view>
						<view class="content">{{ res.question }}</view>
				
						<view v-if="res.imgUrls != null">
							<view class="card-body-img-col3" v-if="res.imgList.length > 1">
								<view class="card-body-img-col3-item" v-for="item in splitImgArr(res.imgList)" :key="item">
									<view v-for="item2 in item" :key="item2">
										<u-image @click="showPic(item2,index)" width="100%" height="200rpx" :src="item2">
										</u-image>
									</view>
								</view>
							</view>
							<view class="card-body-img-col1" v-else>
								<u-image @click="showPic(res.imgList[0],index)" width="100%" height="250rpx"
									:src="res.imgList[0]">
								</u-image>
							</view>
						</view>
				
				
				
						<view class="reply-box" v-if="res.status!=0">
							<view class="item">
								<view class="username">{{ res.answerName }}</view>
								<view class="text">{{ res.answer }}</view>
							</view>
						</view>
						<view class="bottom" v-if="res.status!=0">
							回应时间：{{ res.updateDate }}
						</view>
					</view>
				</view>
				
				
				<u-divider  v-if= "!hasMore" class="index-list-divider" text="没有更多了">
					
				</u-divider>
			</view>
			<view>
				<u-toast ref="uToast" />
			</view>
		</scroll-view>
		<view class="callbackbotton" @click="goCallback()">
			新添反馈
		</view>
		
	</view>
</template>

<script>
	export default {

		data() {
			return {

				list: [{
					name: '未解决'
				}, {
					name: '以解决'
				}],
				current: 0,
				page: 1,
				maxpage: 0,
				hasMore: true,
				commentList: [],
				loading: false,
				status:0
				
			}
		},
		onLoad() {
			this.init()
		},
		methods: {

			// 上拉加载-执行分页
			handleToLower() {
				
				if (this.page < this.maxpage) {
					this.page++
					this.init()
				} else {
					this.hasMore = false
				}
			},
			splitImgArr(data) {

				let result = []
				for (let i = 0; i < data.length; i += 3) {
					result.push(data.slice(i, i + 3))
				}
				return result
			},

			change(index) {

				this.current = index.index
				this.page = 1
				this.hasMore = true
				this.status = index.index
				this.commentList = []
				this.init()
			},
			init() {
			
				this.loading = true
				uni.$u.http.post('/app/issue/list', {
					"page": this.page.toString(),
					"limit": '10',
					"status":this.status
				}).then(res => {
					console.log(res);
					if (res.data.list.length > 0) {
						
						this.maxpage = res.data.totalPage
						this.commentList = [...this.commentList, ...res.data.list];
						this.commentList.forEach(item => {
							if (item.imgUrls != null) {
								item.imgList = item.imgUrls.split(",")
							}
						})
					}
					this.loading = true
				})

			},
			showPic(imgSrc, index) {
				uni.previewImage({
					indicator: 'none',
					current: imgSrc,
					urls: this.commentList[index].imgList,
				})
			},
			goCallback()
			{
				uni.navigateTo({
					url:'./callBack'
				})
			}

		}

	}
</script>

<style lang="scss" scoped>
	.album_scroll_view {
		height: calc(100vh - 36px);
	}

	/* #ifdef H5 */
	.tab-style {
		position: sticky;
		z-index: 9999;
	}

	/* #endif */
	.send-menu {
		padding: 10upx;
		background-color: #2979ff;
		width: 90upx;
		height: 90upx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		border-radius: 100%;
		box-shadow: 1px 3px 13px #939090;
		position: fixed;
		right: 60upx;
		bottom: 120upx;
		z-index: 10;

		>view {
			font-size: 40upx;
			color: #ffffff;
		}
	}

	.nav-search {
		margin-right: 30upx;
	}

	.nav-search-btn {
		margin-right: 30upx;
	}

	.comment {
		display: flex;
		padding: 30rpx;

		.left {
			display: flex;

			.text {
				width: 64rpx;
				height: 64rpx;
			}

			image {
				width: 64rpx;
				height: 64rpx;
				border-radius: 50%;
				background-color: #f2f2f2;
			}
		}

		.right {
			flex: 1;
			padding-left: 10rpx;
			font-size: 30rpx;

			.top {
				display: flex;

				align-items: center;
				margin-bottom: 10rpx;

				.name {
					color: #5677fc;
				}
			}

			.content {
				margin-bottom: 10rpx;
			}


			.reply-box {
				background-color: rgb(242, 242, 242);
				border-radius: 12rpx;

				.item {
					padding: 20rpx;
					border-bottom: solid 2rpx $u-border-color;

					.username {
						font-size: 24rpx;
						color: #999999;
					}
				}

			}

			.card-body-img-col3 {
				width: 100%;

				.card-body-img-col3-item {
					width: 100%;
					display: flex;
					flex-direction: row;

					>view {
						width: 200rpx;
						margin: 2upx;
					}
				}
			}

			.bottom {
				margin-top: 20rpx;
				display: flex;
				font-size: 24rpx;
				color: #9a9a9a;

				.reply {
					color: #5677fc;
					margin-left: 10rpx;
				}
			}



		}


	}
</style>
<style>
	.upload-img .u-delete-icon {
		background-color: #2979ff !important;
	}
	.callbackbotton
	{
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		background-color: skyblue;
		height: 80rpx;
		text-align: center;
		line-height: 80rpx;
		color: #FFFFFF;
		font-size: 45rpx;
		border-radius: 10rpx;
		
		
	}
</style>
